package com.tbit.uqbike.client.util;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.tbit.uqbike.client.pojo.vo.TransferEntity;
import org.apache.http.client.utils.DateUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class DateTimeUtil {
    private final static Logger log = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
    // 用于存放不同模板的日期
    private static final ThreadLocal<Map<String, SimpleDateFormat>> LOCAL = new ThreadLocal<Map<String, SimpleDateFormat>>() {
        @Override
        protected Map<String, SimpleDateFormat> initialValue() {
            return new HashMap<String, SimpleDateFormat>();
        }

    };
    //格式化样本
    private static String forString = "yyyy-MM-dd HH:mm:ss";
    private static String sDay = "yyyy-MM-dd";
    private static String sDay1 = "yyyyMMdd";
    private static String sDay2 = "yyyyMMddHHmmss";
    private static String[] parsePatterns = {forString, "yyyy-MM-dd HH:mm"};
    private static final SimpleDateFormat sdf_hms = new SimpleDateFormat("HHmmss");
    private static String sTime = "HH:mm:ss";

    /**
     * 获取当前时间的时分秒，HHmmss格式的Int
     * @param time 时间
     * @return HHmmss格式的Int
     */
    public static int getHms(Date time) {
        return Integer.parseInt(sdf_hms.format(time));
    }

    public static Date getTomorrowDay() {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat s = getSdf(sDay);
        calender.setTime(new Date());
        calender.add(Calendar.DAY_OF_MONTH, 1);
        String time = s.format(calender.getTime());
        return StringToDateTime(time + " 00:00:00");
    }

    /**
     * 计算两个时间相差的秒数是否在指定时间内
     **/
    public static boolean isInTime(Date startTime, Date endTime, Long time) {
        if (null == startTime || null == endTime) {
            return false;
        }
        long eTime = endTime.getTime();
        long sTime = startTime.getTime();
        long diff = (eTime - sTime) / 1000;
        return diff <= time;
    }

	/*private static SimpleDateFormat sDay = getSdf("yyyy-MM-dd");
	private static SimpleDateFormat sDay1 = getSdf("yyyyMMdd");
	private static SimpleDateFormat sDay2 = getSdf("yyyyMMddHHmmss");
	private static SimpleDateFormat sDay3 = getSdf("yyyy-MM-dd HH:mm:ss");*/

    /**
     * 返回一个SimpleDateFormat,每个线程只会new一次pattern对应的sdf
     *
     * @param pattern
     * @return
     */
    private static SimpleDateFormat getSdf(String pattern) {
        Map<String, SimpleDateFormat> map = LOCAL.get();
        SimpleDateFormat sdf = map.get(pattern);
        if (sdf == null) {
            sdf = new SimpleDateFormat(pattern);
            map.put(pattern, sdf);
        }

        return sdf;
    }

    /**
     * 获取当前时间
     */
    public static String getNowTime() {
        SimpleDateFormat s = getSdf(forString);
        return s.format(new Date());
    }

    /**
     * 获取当前时间往后推一分钟
     */
    public static String getOneMinuteTime() {
        SimpleDateFormat s = getSdf(forString);
        return s.format(System.currentTimeMillis() + 61 * 1000);
    }

    /**
     * 获取当前时间num秒后的时间
     */
    public static String getLastTime(String data, Integer num) {
        try {
            Date date1 = getSdf(forString).parse(data);
            return getSdf(forString).format(date1.getTime() + num * 1000);
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
        return null;
    }

    /**
     * 获取当前时间
     */
    public static String getNowTimeyyyyMMdd() {
        return getSdf(sDay1).format(new Date());
    }

    public static String getDaformatyyyyMMddHHmmss(Date date) {
        return getSdf(sDay2).format(date.getTime());
    }

    /**
     * 获取当前时间往后推61秒
     */
    public static String getNowTimeyyyyMMddHHmmss() {
        return getSdf(sDay2).format(System.currentTimeMillis() + 61 * 1000);
    }

    /**
     * 时间戳转换为Rfc3339标准格式
     * @param timeStamp
     * @return
     */
    public static String timeStampToRfc3339(long timeStamp) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
        return simpleDateFormat.format(new Date(timeStamp));
    }

    /**
     * 获取当前时间往后推61秒
     */
    public static String getOneTimeLast() {
        return getSdf(forString).format(System.currentTimeMillis() + 61 * 1000);
    }

    public static String stringFormatyyyyMMddHHmmss(String time) {
        return getSdf(sDay2).format(StringToDateTime(time));
    }

    /**
     * 获取当前时间(yyyy-MM-dd)
     */
    public static String getNowTimeYMD() {
        return getSdf(sDay).format(new Date());
    }

    /**
     * 获取两个时间差
     */
    public static int getTime(String time1, String time2) {
        SimpleDateFormat s = getSdf(forString);
        int time = 0;
        try {
            time = (int) (s.parse(time2).getTime() - s.parse(time1).getTime()) / 1000;
        } catch (ParseException e) {
            log.error("时间转换出错", e);
        }
        return time;
    }

    /**
     * 日期转字符串
     */
    public static Date StringToDateTime(String dateTime) {
        SimpleDateFormat s = getSdf(forString);
        Date date = new Date();
        try {
            date = s.parse(dateTime);
        } catch (ParseException e) {
            log.error("时间转换出错", e);
        }
        return date;
    }

    /**
     * 字符串转日期类型
     */
    public static String DateTimeToString(Date d) {
        SimpleDateFormat s = getSdf(forString);
        return s.format(d);
    }

    /**
     * 日期获取当天
     */
    public static int getDayOfMonth(Date date) {
        Calendar c = new GregorianCalendar();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 获取月份的天数
     */
    public static int getDayNumOfMonth(Date date) {
        Calendar c = new GregorianCalendar();
        c.setTime(date);
        //判断是不是当月
        Calendar c1 = new GregorianCalendar();
        c1.setTime(new Date());
        if (c.get(Calendar.YEAR) == c1.get(Calendar.YEAR) && c.get(Calendar.MONTH) == c1.get(Calendar.MONTH)) {
            return c1.get(Calendar.DAY_OF_MONTH);
        }
        return c.getActualMaximum(Calendar.DAY_OF_MONTH);
    }

    /**
     * 获取和当前的小时差
     */
    public static Integer getHour(String startTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            Integer baseHour = (int) (time / (60 * 60 * 1000));

            if (time % (60 * 60 * 1000) > 0) {
                baseHour++;
            }

            return baseHour;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 按照用户输入的分钟数计算时间差
     *
     * @param startTime   骑行开始时间
     * @param minuteInput 用户输入的分钟数
     * @param stopTime    停车时间（秒）
     * @return
     */
    public static Integer getMinuteInput(String startTime, Integer minuteInput, Integer stopTime) {
        //如果用户没有输入，则直接返回0
        if (minuteInput == null) {
            return 0;
        }
        SimpleDateFormat s = getSdf(forString);
        try {
            Date oldTime = s.parse(startTime);
            Date nowTime = new Date();
            long inter = nowTime.getTime() - oldTime.getTime() - stopTime * 1000;//两个时间的时间差
            //计算有多少个分钟
            long minuteInputMills = minuteInput * 60 * 1000;//分钟转化为毫秒
            //计算有多少个分钟
            int num = (int) (inter / minuteInputMills);
            if (inter % minuteInputMills > 0) {
                num++;
            }
            return num;
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
        return 0;
    }

    /**
     * 按照用户输入的分钟数计算时间差
     *
     * @param startTime   骑行开始时间
     * @param minuteInput 用户输入的分钟数
     * @param stopTime    停车时间（秒）
     * @return
     */
    public static Integer getMinuteByTime(String startTime, String endTime, Integer minuteInput, Integer stopTime) {
        //如果用户没有输入，则直接返回0
        if (minuteInput == null) {
            return 0;
        }
        SimpleDateFormat s = getSdf(forString);
        try {
            Date oldTime = s.parse(startTime);
            Date nowTime = DateTimeUtil.StringToDateTime(endTime);
            long inter = nowTime.getTime() - oldTime.getTime() - stopTime * 1000;//两个时间的时间差
            //计算有多少个分钟
            long minuteInputMills = minuteInput * 60 * 1000;//分钟转化为毫秒
            //计算有多少个分钟
            int num = (int) (inter / minuteInputMills);
            if (inter % minuteInputMills > 0) {
                num++;
            }
            return num;
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
        return 0;
    }

    /**
     * 获取和当前的小时差（需要减去临时停车的时长）
     */
    public static Integer getHour(String startTime, Integer stopTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            /**临时停车的时间为秒*/
            Long time = time2 - time1 - stopTime * 1000;

            Integer baseHour = (int) (time / (60 * 60 * 1000));

            if (time % (60 * 60 * 1000) > 0) {
                baseHour++;
            }

            return baseHour;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 获取和当前的半小时差
     */
    public static Integer getHalfHour(String startTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            Integer halfHour = (int) (time / (30 * 60 * 1000));

            if (time % (30 * 60 * 1000) > 0) {
                halfHour++;
            }

            return halfHour;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 获取和当前的半小时差
     */
    public static Integer getHalfHour(String startTime, Integer stopTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            Integer halfHour = (int) (time / (30 * 60 * 1000));

            if (time % (30 * 60 * 1000) > 0) {
                halfHour++;
            }

            return halfHour;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 获取两个时间的秒差
     */
    public static Integer getSecondDiffer(String startTime, String endTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Long time = s.parse(endTime).getTime() - s.parse(startTime).getTime();
            return (int) (time / 1000);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return 0;
    }

    /**
     * 获取两个时间的分钟差
     */
    public static long getMinDiffer(String startTime, String endTime) {

        try {
            DateTime dateTime1 = DateUtil.parse(startTime, DatePattern.NORM_DATETIME_PATTERN);
            DateTime dateTime2 = DateUtil.parse(endTime, DatePattern.NORM_DATETIME_PATTERN);
            return DateUtil.between(dateTime1, dateTime2, DateUnit.MINUTE);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return 0;
    }

    /**
     * 获取和当前的分钟差
     */
    public static Integer getMinDiffer(String startTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            Integer minutes = (int) (time / (60 * 1000));

            if (time % (60 * 1000) > 0) {
                minutes++;
            }

            return minutes;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 获取和当前的分钟差
     */
    public static Integer getMinDiffer(String startTime, Integer stopTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            /**减去临时停车时长*/
            Long time = time2 - time1 - stopTime * 1000;

            Integer minutes = (int) (time / (60 * 1000));

            if (time % (60 * 1000) > 0) {
                minutes++;
            }

            return minutes;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 获取和当前的秒差
     */
    public static Integer getSecondDiffer(String startTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            return (int) (time / 1000);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * 指定日期加天数
     */
    public static Date addDay(Date dateTime, int days) {
        Calendar calender = Calendar.getInstance();
        calender.setTime(dateTime);
        calender.add(Calendar.DAY_OF_MONTH, days);

        return calender.getTime();
    }

    /**
     * 指定日期加月份
     */
    public static Date addMonth(Date dateTime, int months) {
        Calendar calender = Calendar.getInstance();
        calender.setTime(dateTime);
        calender.add(Calendar.MONTH, months);

        return calender.getTime();
    }

    /**
     * 是否小于今天
     *
     * @param
     * @return
     */
    public static boolean isBeforeToday(String endDate) {
        if (endDate == null) {
            return false;
        }

        try {
            Long endTime = getSdf(sDay).parse(endDate).getTime() + 24 * 3600 * 1000;
            if (endTime < System.currentTimeMillis()) {
                return true;
            } else {
                return false;
            }
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }

        return false;
    }

    /**
     * 免押是否有效
     */
    public static boolean isDepositValid(String endDate) {
        if (endDate == null) {
            return false;
        }

        try {
            Long endTime = getSdf(sDay).parse(endDate).getTime() + 24 * 3600 * 1000;
            if (endTime > System.currentTimeMillis()) {
                return true;
            } else {
                return false;
            }
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }

        return false;
    }

    public static void main(String[] args) {
        System.out.println(getSecondsUntilMidnight());

        System.out.println(getTime("2024-04-20 18:49:21", "2024-04-20 19:34:23"));

        System.out.println(getHourMinuteSecond("2023-04-24 05:00:00", "2023-04-24 08:30:50"));
        System.out.println(getHourMinuteSecond("2023-04-24 08:00:00", "2023-04-24 08:30:24"));
        System.out.println(getHourMinuteSecond("2023-04-24 08:00:00", "2023-04-24 08:00:26"));
    }

    /**
     * 获取服务器截止日期
     *
     * @param startDate
     * @param
     * @return
     */
    public static String getServiceEndDate(String startDate, Integer type) {
        try {
            /**开始日期为空*/
            if (startDate == null) {
                startDate = getNowTimeYMD();
            }

            /**开始日期小于当前日期*/
            Long startTime = getSdf(sDay).parse(startDate).getTime() + 24 * 3600 * 1000;
            if (startTime < System.currentTimeMillis()) {
                startDate = getNowTimeYMD();
            }

            /**在最新的时间上累加*/
            Calendar calender = Calendar.getInstance();
            calender.setTime(getSdf(sDay).parse(startDate));
            if (type == 0) {//日
                calender.add(Calendar.DATE, 1);
            } else if (type == 1) {//周
                calender.add(Calendar.DATE, 7);
            } else if (type == 2) {//月
                calender.add(Calendar.MONTH, 1);
            } else if (type == 3) {//季
                calender.add(Calendar.MONTH, 3);
            } else if (type == 4) {//半年
                calender.add(Calendar.MONTH, 6);
            } else if (type == 5) {//年
                calender.add(Calendar.YEAR, 1);
            }

            return getSdf(sDay).format(calender.getTime());
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }

        return null;
    }

    /**
     * 获取骑行卡截止日期
     *
     * @param type
     * @return
     */
    public static String getRideCardEndDate(Integer type,Integer days) {
        if (days == null){
            days = 0;
        }
        /**在最新的时间上累加*/
        Calendar calender = Calendar.getInstance();
        if (type == 0 ) {//日
            calender.add(Calendar.DATE, 1);
        } else if (type == 1) {//周
            calender.add(Calendar.DATE, 7);
        } else if (type == 2) {//月
            calender.add(Calendar.MONTH, 1);
        } else if (type == 3) {//季
            calender.add(Calendar.MONTH, 3);
        } else if (type == 4) {//季
            calender.add(Calendar.MONTH, 6);
        } else if (type == 5) {//年
            calender.add(Calendar.YEAR, 1);
        }else if (type == 6) {//固定有效日期
            calender.add(Calendar.DATE, days);
        }
        return getSdf(sDay).format(calender.getTime());
    }

    /**
     * 获取和当前的分钟差
     */
    public static String getMinBefore(Integer minutes) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Long time = System.currentTimeMillis() - minutes * 60 * 1000;

            return s.format(new Date(time));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return null;
    }

    public static String addMinutes(String startTime, Integer minutes) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Long time = StringToDateTime(startTime).getTime() + minutes * 60 * 1000;
            return s.format(new Date(time));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return null;
    }

    public static boolean isDateString(String string) {
        if (string == null) {
            return false;
        }
        try {
            Date date = DateUtils.parseDate(string, parsePatterns);
            if (date != null) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 获取两个时间差
     */
    public static int getTimeDF(String time1, String time2) {
        SimpleDateFormat s = getSdf(forString);
        int time = 0;
        try {
            time = (int) ((s.parse(time2).getTime() - s.parse(time1).getTime()) / 1000);
        } catch (ParseException e) {
            log.error("时间转换出错", e);
        }
        return time;
    }

    public static Integer getMinuteInput(String startTime, Integer minuteInput, Integer stopTime, String endTime) {
        //如果用户没有输入，则直接返回0
        if (minuteInput == null) {
            return 0;
        }
        SimpleDateFormat s = getSdf(forString);
        try {
            Date oldTime = s.parse(startTime);
            Date nowTime = s.parse(endTime);
            long inter = nowTime.getTime() - oldTime.getTime() - stopTime * 1000;//两个时间的时间差
            //计算有多少个分钟
            long minuteInputMills = minuteInput * 60 * 1000;//分钟转化为毫秒
            //计算有多少个分钟
            int num = (int) (inter / minuteInputMills);
            if (inter % minuteInputMills > 0) {
                num++;
            }
            return num;
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
        return 0;
    }

    /**
     * 求两个时间时分秒
     *
     * @param startTime
     * @param endTime
     * @return
     */
    public static String getHourMinuteSecond(String startTime, String endTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date oldTime = s.parse(startTime);
            Date nowTime = s.parse(endTime);
            long inter = nowTime.getTime() - oldTime.getTime();//两个时间的时间差
            //计算小时
            long hour = inter / 60 / 60 / 1000;
            //计算有多少个分钟
            long minute = (inter - (hour * 3600 * 1000)) / 60 / 1000;//分钟转化为毫秒
            //计算有多少秒
            long second = (inter - (hour * 3600 * 1000) - (minute * 60 * 1000)) / 1000;
            StringBuffer stringBuffer = new StringBuffer();
            if (hour > 0) {
                stringBuffer.append(hour).append("小时").append(minute).append("分钟").append(second).append("秒");
                return stringBuffer.toString();
            } else if (hour == 0 && minute > 0) {
                stringBuffer.append(minute).append("分钟").append(second).append("秒");
                return stringBuffer.toString();
            } else {
                stringBuffer.append(second).append("秒");
                return stringBuffer.toString();
            }
        } catch (ParseException e) {
            log.error(e.getMessage(), e);
        }
        return null;
    }

    /**
     * @return 当前时间到明天0点相差的秒数
     */
    public static long getSecondsUntilMidnight() {
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();

        // 设置明天的凌晨时间（即今天的午夜，明天的00:00:00）
        LocalDateTime midnightTomorrow = LocalDateTime.of(now.toLocalDate().plusDays(1), LocalTime.MIDNIGHT);

        // 计算时间差
        Duration duration = Duration.between(now, midnightTomorrow);

        // 获取秒数
        return duration.getSeconds();
    }


    public static Double test(TransferEntity transferEntity) {
        transferEntity.setFreeRide(true);
        transferEntity.setFreeRideOverTime(true);
        return 0.0;
    }


    public static int test(String startTime, String endTime) {
        SimpleDateFormat s = getSdf(forString);
        try {
            Date date1 = s.parse(startTime);
            Date date2 = s.parse(endTime);

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;

            Integer minutes = (int) (time / (60 * 1000));

            if (time % (60 * 1000) > 0) {
                minutes++;
            }

            return minutes;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * @description: 获取当前时间和传入时间的毫秒差
     * @author: mo.shanyong
     * @date: 2024/12/2 14:48
     * @param: date 时间字符串，0000-00-00 00:00:00
     * @return: long
     */
    public static long checkTimeAndNowInterval(String date){
        SimpleDateFormat sdf = getSdf(forString);
        try {
            Date date1 = sdf.parse(date);
            Date date2 = new Date();

            Long time1 = date1.getTime();
            Long time2 = date2.getTime();

            Long time = time2 - time1;
            return time;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        return 0;
    }

    /**
     * @description: 获取yyyy-MM-dd HH:mm:ss的时间格式format
     * @author: mo.shanyong
     * @date: 2024/12/2 15:25
     * @return: java.text.SimpleDateFormat
     */
    public static SimpleDateFormat getSdf_yyyyMMddHHmmss(){
        return getSdf(forString);
    }

    /**
     * @description: 获取日期格式
     * @author: mo.shanyong
     * @date: 2025/2/20 16:43
     * @param: date
     * @return: java.lang.String
     */
    public static String getYMDStrByDate(Date date){
        SimpleDateFormat dateFormat = new SimpleDateFormat(sDay);
        return dateFormat.format(date);
    }

    /**
     * @description: 根据日期时间字符串获取日期时间
     * @author: mo.shanyong
     * @date: 2025/2/7 17:45
     * @param: dateTimeStr 日期时间字符串，格式必须是yyyy-MM-dd HH:mm:ss
     * @return: java.time.LocalDateTime
     */
    public static LocalDateTime getLocalDateTimeByStr(String dateTimeStr){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(forString);
        return LocalDateTime.parse(dateTimeStr,formatter);
    }
    /**
     * @description: 根据日期字符串获取日期（2025-04-01）
     * @author: mo.shanyong
     * @date: 2025/4/11 15:27
     * @param: date 日期字符串，格式必须是yyyy-MM-dd
     * @return: java.time.LocalDate
     */
    public static LocalDate getLocalDateByStr(String date){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(sDay);
        return LocalDate.parse(date,formatter);
    }

    /**
     * @description: 根据日期字符串获取日期（14:01:30）
     * @author: mo.shanyong
     * @date: 2025/4/11 15:29
     * @param: time 时间字符串，格式必须是HH:mm:ss
     * @return: java.time.LocalTime
     */
    public static LocalTime getLocalTimeByStr(String time){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(sTime);
        return LocalTime.parse(time,formatter);
    }

    /**
     * @description: 把data转换成LocalDateTime
     * @author: mo.shanyong
     * @date: 2025/5/13 15:18
     * @param: date
     * @return: java.time.LocalDateTime
     */
    public static LocalDateTime getLocalDateTimeByDate(Date date){
        return getLocalDateTimeByStr(DateTimeToString(date));
    }
    /**
     * @description: 获取时间字符串
     * @author: mo.shanyong
     * @date: 2025/6/3 13:36
     * @param: localDateTime
     * @return: java.lang.String
     */
    public static String getTimeStrByLocalDateTime(LocalDateTime localDateTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(forString);
        return formatter.format(localDateTime);
    }

}
